package cn.stylefeng.guns.modular.shuheng.warpper;

import cn.stylefeng.guns.core.common.constant.factory.ConstantFactory;
import cn.stylefeng.guns.core.shiro.ShiroKit;
import cn.stylefeng.guns.core.shiro.ShiroUser;
import cn.stylefeng.guns.core.util.DateUtil;
import cn.stylefeng.roses.core.base.warpper.BaseControllerWrapper;
import cn.stylefeng.roses.kernel.model.page.PageResult;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import java.util.List;
import java.util.Map;

public class DataWrapper extends BaseControllerWrapper {

    public DataWrapper(Map<String, Object> single) {
        super(single);
    }

    public DataWrapper(List<Map<String, Object>> multi) {
        super(multi);
    }

    public DataWrapper(Page<Map<String, Object>> page) {
        super(page);
    }

    public DataWrapper(PageResult<Map<String, Object>> pageResult) {
        super(pageResult);
    }

    @Override
    protected void wrapTheMap(Map<String, Object> map) {
        ShiroUser user = ShiroKit.getUser();
        boolean flag = ConstantFactory.me().getFilesByDataIdAndUser((Long)map.get("dataId"),user)!=null;
        map.put("hasUpload", flag?"是":"否");
        Integer year = (Integer) map.get("dataYear");
        Integer month = (Integer) map.get("dataMonth");
        map.put("status","0");
        if(DateUtil.getNowYear()==year){
            if(DateUtil.getNowMonth()==month){
                //当月要完成的任务
                map.put("status","1");
                if(DateUtil.getNowDay()>=20 && !flag){
                    //已经到当月20号还没有完成的任务
                    map.put("status",2);
                }
            }
        }
    }
}